package com.woniuxy.lab.woniu_lab_boss.Security;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniuxy.lab.woniu_lab_boss.common.Result;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 17292
 */
@Slf4j
public class SecurityUtil {


    public static void requestResult(HttpServletResponse httpServletResponse, String msg, Integer code) throws IOException {
        log.info(msg);
        Result result = Result.success(code, msg,null);
        ObjectMapper objectMapper = new ObjectMapper();
        String resultToString = objectMapper.writeValueAsString(result);

        httpServletResponse.setCharacterEncoding("utf8");
        httpServletResponse.setContentType("application/json;charset=utf8");

        PrintWriter writer = httpServletResponse.getWriter();
        writer.write(resultToString);
        writer.flush();
    }
}
